#!/bin/sh
#
# description: Starts and stops the vsftpd daemon
#
mos=/usr/local/etc/mos

case "$1" in
  start)
	echo "Starting vsftpd service..."
	[ -z "$( cat /usr/local/etc/passwd | grep 'root:/:/bin/sh' )" ] && sed -i 's/root::\/bin/root:\/:\/bin/' /usr/local/etc/passwd
	$mos/vsftpd/vsftpd $mos/vsftpd/vsftpd.conf&
	;;
  stop)
	echo "Shutting down vsftpd services..."
	[ ! -z "$( cat /usr/local/etc/passwd | grep 'root:/:/bin/sh' )" ]  && sed -i 's/root:\/:\/bin/root::\/bin/' /usr/local/etc/passwd
	killall -9 vsftpd
	;;
  status)
	stat=`ps -a | grep vsftpd | sed '/grep/d/status/d'`
	if [ -z "$stat" ] ; then
		echo "vsftpd is stopped"
	else
		echo "vsftpd is running"
	fi
	;;
  enable)
	echo "Enabling vsftpd..."
	[ -z "$( cat /usr/local/etc/passwd | grep 'ftp::1001' )" ] && echo "ftp::1001:0:ftp:/tmp/usbmounts:/bin/sh" >> /usr/local/etc/passwd
	;;
  disable)
	echo "Disabling vsftpd..."
	[ ! -z "$( cat /usr/local/etc/passwd | grep 'ftp::1001' )" ] &&  sed -i '/^ftp::1001/d' /usr/local/etc/passwd
	;;
  *)
	echo "Usage: $0 {start|stop|status|enable|disable}"
esac

exit $?
